//
//  NSArray+Extention.m
//  whereToEatMerchat
//
//  Created by WTFSSD on 2017/7/3.
//  Copyright © 2017年 WTFSSD. All rights reserved.
//

#import "NSArray+Extention.h"

@implementation NSArray (Extention)


-(NSArray *)map:(id (^)(id, int))block{
    NSMutableArray * marr = [NSMutableArray array];
    
    for (int i = 0; i<self.count; i++) {
        id obj = block(self[i],i);
        if (!obj) {
            continue;
        }
        [marr addObject:obj];
    }
    return [NSArray arrayWithArray:marr];
}


-(NSArray *)distinct{
    NSMutableArray * marr = [NSMutableArray array];
    [self map:^id(id obj, int index) {
        if ([marr indexOfObject:obj]==NSNotFound) {
            [marr addObject:obj];
        }
        return nil;
    }];
    
    return [NSArray arrayWithArray:marr];
}
@end
